from product_upload.util.basic.mysql_util import db_get_one, get_amazon_us_upload_and_lock_task


class AmazonUsUpload:
    # 字段顺序与数据库字段一致
    fields = ['id', 'status', 'opt_name', 'shop', 'brand', 'brand_zip', 'basic_platform', 'class_name', 'product_type',
              'upload_limit', 'create_time', 'update_time', 'remark', 'update_by']

    def __init__(self, **kwargs):
        self.id = kwargs.get('id', None)
        self.status = kwargs.get('status', None)
        self.opt_name = kwargs.get('opt_name', None)
        self.shop = kwargs.get('shop', None)
        self.brand = kwargs.get('brand', None)
        self.brand_zip = kwargs.get('brand_zip', None)
        self.basic_platform = kwargs.get('basic_platform', None)
        self.class_name = kwargs.get('class_name', None)
        self.product_type = kwargs.get('product_type', None)
        self.upload_limit = kwargs.get('upload_limit', None)
        self.create_time = kwargs.get('create_time', None)
        self.update_time = kwargs.get('update_time', None)
        self.remark = kwargs.get('remark', None)
        self.update_by = kwargs.get('update_by', None)

    @classmethod
    def from_db(cls, field_names, row) -> 'AmazonUsUpload':
        if len(field_names) != len(row):
            raise ValueError("bug!---db field len != query field len")
        data_dict = dict(zip(field_names, row))
        return cls(**data_dict)

    def __repr__(self):
        field_info = []
        for field in self.fields:
            value = getattr(self, field)
            field_info.append(f"{field}={repr(value)}")
        return f"AmazonUsUpload=[{', '.join(field_info)}]"


if __name__ == '__main__':
    print(get_amazon_us_upload_and_lock_task(",".join(AmazonUsUpload.fields), None))
    pass
